home *** CD-ROM | disk | FTP | other *** search
/ Mac Power 1997 November / MACPOWER-1997-11.ISO.7z / MACPOWER-1997-11.ISO / Apple関連 / ResEdit 2.1.3 / Examples / CExamples / Source / ICON.LDEF.c next >
Text File  |  1994-09-14  |  2KB  |  64 lines

  1. /*
  2.  COPYRIGHT (C) 1984-1990 Apple Computer,Inc.
  3.  All rights reserved
  4. */
  5.  
  6. #include    <types.h>
  7. #include    <memory.h>
  8. #include    <menus.h>
  9. #include    <resources.h>
  10. #include    <lists.h>
  11. #include    <ToolUtils.h>
  12.  
  13. #include    "ResEd.h"
  14.  
  15. #define IconSize 128
  16.  
  17. pascal void DrawIcon (Rect *lRect, Handle theIcon)
  18.  
  19. {
  20. if (SizeResource(theIcon) >= IconSize)
  21.     PlotIcon(lRect, theIcon);
  22. }
  23.  
  24. /* This routine simply looks up in the list at the given cell, extracts the ID and
  25.     gets the resource called for.  Returns NIL if not found.  Note, this assumes
  26.     the resfile is set up correctly.
  27.     NOTE:  This is used by both ICON and ICN# pickers. */
  28. Handle IconFetch (Cell lCell, ListHandle lHandle, short *id, Boolean *wasLoaded)
  29. {
  30.     short                err;
  31.     short             len = 2;
  32.     Handle            tempH = nil;
  33.     PickHandle     tempPick;
  34.     
  35.     LGetCell((Ptr)id, &len, lCell, lHandle);            /* Get the ID from the list.    */
  36.     if (len == 2) {                                                                /* ID must be 2 bytes.                */
  37.         /* Load the resource since we want to draw it.                                                         */
  38.         tempPick = (PickHandle)((*lHandle)->refCon);
  39.     tempH = REGet1ResourceSpecial((*tempPick)->theResFile, (*tempPick)->rType, *id, wasLoaded, &err);        
  40.         }
  41.     return tempH;
  42. }
  43.  
  44. /* This is the custom drawProc for the list (which contains the resource ID's).  It
  45.     simply draws the icon in the given rect and frames a selection rect around it (if
  46.     necessary). */
  47. pascal void  DrawCell(short message, Boolean lSelect, Rect *lRect, Point lCell,
  48.                            short lDataOffset, short lDataLen, ListHandle lHandle)
  49. {
  50.     Handle theIcon;
  51.     short id;
  52.     Boolean wasLoaded;
  53.     
  54.     #pragma    unused (lDataOffset, lDataLen)    /* Not needed here.                                */
  55.  
  56.     if ((message == lDrawMsg) || (message == lHiliteMsg)) {
  57.         theIcon = IconFetch(lCell, lHandle, &id, &wasLoaded);
  58.         DrawLDEF (message, lSelect, lRect, theIcon, id, "¥p", 32, 32, DrawIcon, lHandle);
  59.         
  60.         if ((theIcon != nil) && (!wasLoaded))
  61.             HPurge(theIcon);
  62.         }
  63. }
  64.